package com.example;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

/**
 * @Author 郅占伟
 * @ClassName MP3Player
 * @Description: TODO
 * @Date 2023年11月27日
 * @Version: 1.0
 */
public class MP3Player {
    static Player player = null;

    public static void main(String[] args) throws FileNotFoundException, JavaLayerException {
        File file = new File("F:\\QQ音乐\\QQMusic下载\\猫瑾 - 朗朗晴天.mp3");
        FileInputStream fis = new FileInputStream(file);
        BufferedInputStream stream = new BufferedInputStream(fis);
        Player player = new Player(stream);
        player.play();
    }

    /**
     * 播放 20 秒并结束播放
     */
    public void play() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    File file = new File("F:\\QQ音乐\\QQMusic下载\\猫瑾 - 朗朗晴天.mp3");
                    FileInputStream fis = new FileInputStream(file);
                    BufferedInputStream stream = new BufferedInputStream(fis);
                    player = new Player(stream);
                    player.play();
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
        }).start();
        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        player.close();
    }


}
